home *** CD-ROM | disk | FTP | other *** search
/ Alles Voor Internet / Tout Pour Internet / alles voor internet.iso / MacInternet™ / Telnet / NCSA / tn3270 2.3d26 source / tn3270 tools / genattn.c next >
C/C++ Source or Header  |  1991-01-21  |  8KB  |  349 lines

  1. /*
  2.  *  tn3270 for the Macintosh Source Code
  3.  *  Brown University Computing and Information Services
  4.  *  Version 2.3d21, January 17, 1991
  5.  *  Copyright (c) 1988, 1989, 1990, 1991 by Brown University and by
  6.  *  Peter John DiCamillo.
  7.  *
  8.  *  Permission is granted to any individual or institution to use, copy,
  9.  *  or redistribute the binary version of this software and its
  10.  *  documentation provided this notice and the copyright notices are
  11.  *  retained.  Permission is granted to any individual or non-profit
  12.  *  institution to use, copy, modify, or redistribute the source files
  13.  *  of this software provided this notice and the copyright notices are
  14.  *  retained.  This software may not be distributed for profit, either
  15.  *  in original form or in derivative works, nor can the source be
  16.  *  distributed to other than an individual or a non-profit institution.
  17.  *  Any  individual or group interested in seeing and/or using these
  18.  *  source files but who are prevented from doing so by the above
  19.  *  constraints should contact Don Wolfe, Assistant Vice-President for
  20.  *  Computer Systems at Brown University, (401) 863-7250, for possible
  21.  *  software licensing of the source developed at Brown.
  22.  *
  23.  *  Brown University and Peter John DiCamillo make no representations
  24.  *  about the suitability of this software for any purpose.
  25.  *
  26.  *  BROWN UNIVERSITY AND PETER JOHN DICAMILLO GIVE NO WARRANTY, EITHER
  27.  *  EXPRESS OR IMPLIED, FOR THE PROGRAM AND/OR DOCUMENTATION PROVIDED,
  28.  *  INCLUDING, WITHOUT LIMITATION, WARRANTY OF MERCHANTABILITY AND
  29.  *  WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE.
  30.  *
  31.  */
  32.  
  33. #define fileMenu    256
  34. #include <Quickdraw.h>
  35. #include <Fonts.h>
  36. #include <Windows.h>
  37. #include <Menus.h>
  38. #include <Dialogs.h>
  39. #include <Memory.h>
  40. #include <SegLoad.h>
  41. #include <Events.h>
  42. #include <Desk.h>
  43. #include <fcntl.h>
  44.  
  45. char done;                /* flag for mainline to return */
  46.  
  47. struct Rect screenRect, dragRect, pRect, sizeRect;
  48. struct WindowRecord wRecord;
  49. struct GrafPort *myWindow;
  50. MenuHandle myMenus[1];
  51.  
  52. char * name1[32] =
  53.     {"PF1", "PF2", "PF3", "PF4", "PF5", "PF6",
  54.      "PF7", "PF8", "PF9", "PF10", "PF11", "PF12",
  55.      "PF13", "PF14", "PF15", "PF16", "PF17",
  56.      "PF18", "PF19", "PF20", "PF21", "PF22",
  57.      "PF23", "PF24", "Sys", "Clear", "PA1",
  58.      "PA2", "Erase", "Insert", "Delete", "Insert"};
  59. char * name2[32] =
  60.     {"", "", "", "", "", "", "", "",
  61.      "", "", "", "", "", "", "", "",
  62.      "", "", "", "", "", "", "", "",
  63.      "Req", "", "", "", "EOF", "Mode",
  64.      "Char", "Char"};
  65.  
  66. main()
  67. {
  68. short rc;
  69.  
  70. macinit();                /* general Mac initialization */
  71. defattn(0);
  72. done = 0;
  73. while (!done) hndmac();
  74. }
  75.  
  76. macinit()
  77. {
  78.  
  79.             /* set-up general Macintosh environment */
  80. InitGraf(&qd.thePort);
  81. InitWindows();
  82. InitFonts();
  83. InitMenus();
  84. InitDialogs(0L);
  85. InitCursor();
  86.  
  87. myMenus[0] = NewMenu(fileMenu, "File");
  88. AppendMenu(myMenus[0], "Save");
  89. AppendMenu(myMenus[0], "Quit");
  90. InsertMenu(myMenus[0], 0);
  91. DrawMenuBar();
  92.  
  93. screenRect = qd.screenBits.bounds;
  94. SetRect(&dragRect, 4, 24, screenRect.right-4, screenRect.bottom-4);
  95.  
  96. pRect.top = 23;
  97. pRect.left = 5;
  98. pRect.bottom = 337;
  99. pRect.right = 505;
  100.  
  101. sizeRect.top = 25;
  102. sizeRect.left = 25;
  103. sizeRect.bottom = 296;
  104. sizeRect.right = 501;
  105.  
  106. myWindow = NewWindow(&wRecord, &pRect, "genattn",
  107.             true, 3, -1L, 0, 0L);
  108. SetPort(myWindow);
  109. pRect = qd.thePort->portRect;
  110. }
  111.  
  112. hndmac()
  113. {
  114.     register short code;
  115.     register unsigned short i, w, h;
  116.     register long l;
  117.     GrafPtr gp;
  118.     long pt;
  119.     struct EventRecord myEvent;
  120.     struct GrafPort *whichWindow;
  121.  
  122.     /* handle system events */
  123.         SystemTask();
  124.         if (!GetNextEvent(everyEvent, &myEvent)) return;
  125.         switch(myEvent.what) {
  126.         case mouseDown:
  127.             code = FindWindow(&myEvent.where, &whichWindow);
  128.             switch (code) {
  129.             case inMenuBar:
  130.                 docommand(MenuSelect(&myEvent.where));
  131.                 break;
  132.             case inSysWindow:
  133.                 SystemClick(&myEvent, whichWindow);
  134.                 break;
  135.             case inDrag:
  136.                 DragWindow(whichWindow, &myEvent.where, &dragRect);
  137.                 break;
  138.             case inGrow:
  139.                 if (whichWindow == FrontWindow()) {
  140.                     l = GrowWindow(whichWindow, &myEvent.where,
  141.                                 &sizeRect);
  142.                     h = l >> 16;
  143.                     w = l & 0x0000ffffL;
  144.                     SizeWindow(whichWindow, w, h, true);
  145.                     }
  146.                 break;
  147.             case inContent:
  148.                 if (whichWindow != FrontWindow()) {
  149.                     SelectWindow(whichWindow);
  150.                     }
  151.                 break;
  152.             }
  153.             break;
  154.  
  155.         case mouseUp:
  156.             break;
  157.  
  158.         case keyDown:
  159.         case autoKey:
  160.             break;
  161.  
  162.         case activateEvt:
  163.             break;
  164.  
  165.         case updateEvt:
  166.             BeginUpdate((WindowPtr)myEvent.message);
  167.             EndUpdate((WindowPtr)myEvent.message);
  168.             break;
  169.  
  170.         default:    break;
  171.         }
  172. }
  173.  
  174. docommand(mResult)
  175. long mResult;
  176. {
  177.     register short theItem, theMenu;
  178.     register char name[40];
  179.  
  180.     theMenu = mResult >> 16;
  181.     theItem = mResult;
  182.     switch(theMenu) {
  183.         case fileMenu:
  184.             switch (theItem) {
  185.                 case 1: defattn(1);
  186.                         done = 1;
  187.                         break;
  188.                 case 2: done = 1;
  189.                         break;
  190.                 default:
  191.                         break;
  192.                 }
  193.             break;
  194.         default:
  195.             break;
  196.         }
  197.         HiliteMenu(0);
  198. }
  199.  
  200. defattn(save)
  201. char save;
  202. {
  203. Rect mr;
  204. Rect keyrect;
  205. Rect framerect;
  206. register short i, j;
  207. short fd, keynum;
  208. char hexline[120];
  209. BitMap menumap;
  210. GrafPtr currport;
  211. unsigned char * bitptr;
  212.  
  213. mr.top = 40;
  214. mr.left = 66;
  215. mr.bottom = mr.top + 101;
  216. mr.right = mr.left + 343; 
  217.  
  218. /* entire menu (done by menu manager) */
  219. framerect.top = mr.top - 1;
  220. framerect.left = mr.left - 1;
  221. framerect.bottom = mr.bottom + 1;
  222. framerect.right = mr.right + 1;
  223. FrameRect(&framerect);
  224.  
  225. /* pf1-12 */
  226. framerect.top = mr.top + 1;
  227. framerect.left = mr.left + 1;
  228. framerect.bottom = mr.bottom - 1;
  229. framerect.right = mr.left + 127;
  230. FrameRect(&framerect);
  231.  
  232. keynum = 0;
  233. keyrect.top = mr.top + 3;
  234. keyrect.bottom = keyrect.top + 23;
  235. for (i = 0; i < 4; i++) {
  236.     keyrect.left = mr.left + 3;
  237.     keyrect.right = keyrect.left + 40;
  238.     for (j=0; j < 3; j++) {
  239.         FrameRect(&keyrect);
  240.         addtext(&keyrect, name1[keynum], name2[keynum]);
  241.         keynum++;
  242.         keyrect.left += 41;
  243.         keyrect.right += 41;
  244.         }
  245.     keyrect.top += 24;
  246.     keyrect.bottom += 24;
  247.     }
  248.  
  249. /* pf13-24 */
  250. framerect.top = mr.top + 1;
  251. framerect.left = mr.left + 216;
  252. framerect.bottom = mr.bottom - 1;
  253. framerect.right = mr.left + 342;
  254. FrameRect(&framerect);
  255. keyrect.top = mr.top + 3;
  256. keyrect.bottom = keyrect.top + 23;
  257. for (i = 0; i < 4; i++) {
  258.     keyrect.left = mr.left + 218;
  259.     keyrect.right = keyrect.left + 40;
  260.     for (j=0; j < 3; j++) {
  261.         FrameRect(&keyrect);
  262.         addtext(&keyrect, name1[keynum], name2[keynum]);
  263.         keynum++;
  264.         keyrect.left += 41;
  265.         keyrect.right += 41;
  266.         }
  267.     keyrect.top += 24;
  268.     keyrect.bottom += 24;
  269.     }
  270.  
  271. /* special keys */
  272. framerect.top = mr.top + 1;
  273. framerect.left = mr.left + 129;
  274. framerect.bottom = mr.bottom - 1;
  275. framerect.right = mr.left + 214;
  276. FrameRect(&framerect);
  277. keyrect.top = mr.top + 3;
  278. keyrect.bottom = keyrect.top + 23;
  279. for (i = 0; i < 4; i++) {
  280.     keyrect.left = mr.left + 131;
  281.     keyrect.right = keyrect.left + 40;
  282.     for (j=0; j < 2; j++) {
  283.         FrameRect(&keyrect);
  284.         addtext(&keyrect, name1[keynum], name2[keynum]);
  285.         keynum++;
  286.         keyrect.left += 41;
  287.         keyrect.right += 41;
  288.         }
  289.     keyrect.top += 24;
  290.     keyrect.bottom += 24;
  291.     }
  292.  
  293. if (save == 0) return;
  294.  
  295. bitptr = (unsigned char *)NewPtr(4448L);
  296. menumap.baseAddr = (Ptr)bitptr;
  297. for (i=0; i < 4448; i++) *(bitptr + i) = 0;
  298. menumap.rowBytes = 44;
  299. menumap.bounds.top = 0;
  300. menumap.bounds.left = 0;
  301. menumap.bounds.bottom = mr.bottom - mr.top;
  302. menumap.bounds.right = mr.right - mr.left;
  303. GetPort(&currport);
  304. CopyBits(&(currport->portBits), &menumap, &mr, &(menumap.bounds),
  305.         srcCopy, 0L);
  306. fd = open("hd:mpw:tn3270:attnmap.hex", O_CREAT+O_WRONLY);
  307. for (i=0; i < 4448; i+= 8) {
  308.     sprintf(hexline, "%02x%02x %02x%02x %02x%02x %02x%02x\n",
  309.             *(bitptr+i), *(bitptr+i+1),
  310.             *(bitptr+i+2), *(bitptr+i+3),
  311.             *(bitptr+i+4), *(bitptr+i+5),
  312.             *(bitptr+i+6), *(bitptr+i+7));
  313.     write(fd, hexline, strlen(hexline));
  314.     }
  315. close(fd);
  316. DisposPtr(bitptr);
  317. }
  318.  
  319. addtext(key, name1, name2)
  320. Rect * key;
  321. char * name1;
  322. char * name2;
  323. {
  324. short w;
  325.  
  326. TextFont(3);
  327. if (name2[0] == 0) {
  328.     TextSize(12);
  329.     w = StringWidth(name1);
  330.     if (w > 38) w = 38;
  331.     w = (38-w)/2;
  332.     MoveTo((*key).left+w+1, (*key).bottom-7);
  333.     DrawString(name1);
  334.     }
  335. else {
  336.     TextSize(9);
  337.     w = StringWidth(name1);
  338.     if (w > 38) w = 38;
  339.     w = (38-w)/2;
  340.     MoveTo((*key).left+w+1, (*key).bottom-13);
  341.     DrawString(name1);
  342.     w = StringWidth(name2);
  343.     if (w > 38) w = 38;
  344.     w = (38-w)/2;
  345.     MoveTo((*key).left+w+1, (*key).bottom-4);
  346.     DrawString(name2);
  347.     }
  348. }
  349.